package org.example.test.controller;

import org.example.test.entity.User;
import org.example.test.entity.users;
import org.example.test.mapper.UserMapper;
import org.example.test.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

//@Controller
@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserMapper userMapper;

    @Autowired
    private UserService userService;
    /**
     * 全部查询！
     *
     * @return
     */
    @GetMapping("/hellos")
    public List<User> hellos() {
        System.out.println("1234678");
        return userMapper.findAll();
    }

    /**
     * 新增、更新！
     * @param user
     * @return
     */
    @PostMapping("/insert")
    public Integer save(@RequestBody User user){
        //新增或者更新
        return userService.save(user);
    }
    @DeleteMapping("/delete/{id}")
    public Integer delete(@PathVariable Integer id){
        return userMapper.deleteById(id);
    }



//    @GetMapping("/hello")
//    public String hello() {
//        return "ok";
//    }
//    @RequestMapping("/getUser")
//    public String getUser(String userName,String passWord) {
//        System.out.println(userName);
//        System.out.println(passWord);
//        return "ok";
//    }
//    @RequestMapping("/getaihao")
//    public String getaihao(Integer aihao[]) {
//        System.out.println(Arrays.toString(aihao));
//        return "oks";
//    }
//    @RequestMapping("/bean")
//    public String bean(users users) {
//        System.out.println(users);
//        return "oks";
//    }
//    @RequestMapping("/ces")
//    public users beans() {
//        users u = new users();
//        u.setName("zhangsan");
//        u.setAge(20);
//        u.setPassword("123");
//        return u;
//    }
//
//    @RequestMapping("/setusers")
//    public String setusers(@RequestParam("name") String userName, @RequestParam("password") String passWord) {
//        System.out.println(userName);
//        System.out.println(passWord);
//        return "oksss";
//    }
}
